package com.yunfeisoft.business.dao.impl;

import com.yunfeisoft.base.model.User;
import com.yunfeisoft.business.dao.inter.FamilySatisfactionQuestionnaireDao;
import com.yunfeisoft.business.model.FamilySatisfactionQuestionnaire;
import com.yunfeisoft.business.model.Room;
import com.yunfeisoft.common.base.BaseDaoImpl;
import com.yunfeisoft.common.sql.builder.SelectBuilder;
import com.yunfeisoft.common.sql.builder.WhereBuilder;
import com.yunfeisoft.common.utils.Page;
import org.springframework.stereotype.Repository;

import java.util.Map;

/**
 * ClassName: FamilySatisfactionQuestionnaireDaoImpl
 * Description: 家属满意度调查表Dao实现
 * Author: Jackie liu
 * Date: 2020-05-22
 */
@Repository
public class FamilySatisfactionQuestionnaireDaoImpl extends BaseDaoImpl<FamilySatisfactionQuestionnaire, String> implements FamilySatisfactionQuestionnaireDao {

    @Override
    public Page<FamilySatisfactionQuestionnaire> queryPage(Map<String, Object> params) {
        WhereBuilder wb = new WhereBuilder();
        wb.setOrderByWithDesc("createTime");
        if (params != null) {
            initPageParam(wb, params);
        }
        SelectBuilder builder = getSelectBuilder("f");
        builder.column("r.roomNum as roomNum")
                .column("r.floorNum as floorNum")
                .leftJoin(Room.class).alias("r")
                .on("r.id = f.roomId").build();
        builder.column("u1.name as mostSatisfactionPersonName")
                .leftJoin(User.class).alias("u1")
                .on("f.mostSatisfactionPerson = u1.id").build();
        builder.column("u2.name as mostDissatisfiedPersonName")
                .leftJoin(User.class).alias("u2")
                .on("f.mostDissatisfiedPerson = u2.id").build();
        return queryPage(builder.getSql(), wb);
    }
}